<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div><input type="text" v-model="word"><button @click="addTodo">add</button></div>
        <ul>
            <li v-for="todo in todos">
                {{todo.text}}
            </li>
            {{activeCount}} {{todos.length}}
        </ul>
    </div>
</body>
<script type="module">
    import { createApp, reactive ,computed ,ref} from '../node_modules/vue/dist/vue.esm-browser.js'
    let data = [{
        text: '吃饭',
        completed: true
    }, {
        text: '看书',
        completed: false
    },{
        text: '敲代码',
        completed: false
    }]
    
    createApp({
        setup() {
            const todos = reactive(data)
            let word = ref('')
            const activeCount = computed(() => todos.filter(item => !item.completed).length)
            return {
                todos,
                activeCount,
                word,
                addTodo(){
                    if(!word){
                        return
                    }
                    todos.push({
                        text:word.value,
                        completed: false
                    })
                    word.value =''
                }
            }
        }
        
    }).mount('#app')
</script>

</html>